'use strict';
module.exports = {
	/**
	 * 获取发布贴子详情
	 * @url client/bbs/pub/squareItemDetail 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid } = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------

		res.data = await vk.baseDao.selects({
			dbName: "bbs_article",
			whereJson: { _id: data._id },
			getOne: true, // 只返回第一条数据
			getMain: true, // 直接返回数据库查询到的数据（不带code,rows等参数）
			limit: 1,
			foreignDB: [{
					dbName: "user-bbs-tumbup",
					localKey: "_id",
					foreignKey: "posts_id",
					as: "tumbups",
					fieldJson: { _id: true }
				}, {
					dbName: "user-bbs-tumbup",
					localKey: "_id",
					foreignKey: "posts_id",
					as: "tumbup",
					fieldJson: { _id: true },
					whereJson: { user_id: uid },
					limit: 1,
				}, {
					dbName: "uni-id-users",
					localKey: "uid",
					foreignKey: "_id",
					as: "user",
					fieldJson: { nickname: true, avatar: true },
					limit: 1,
				},
				{
					dbName: "bbs_category",
					localKey: "category_id",
					foreignKey: "_id",
					as: "categoey",
					fieldJson: { name: true },
					limit: 1,
				},
			]
		});
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
